﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TestsModel.Data;
using TestsModel.Enums;

namespace TestContentTool.TestControls
{
    public partial class RadioTestControl : UserControl, IIdentifiableTestControl
    {
        private string id = Guid.NewGuid().ToString();
        public string Id { get { return id; } }
        public TestTypes TestType { get{return TestTypes.RadioTest;} }
        public string Display { get { return radioTestQestionTextBox.Text; } }

        private RadioTest radioTest;

        public RadioTestControl()
        {
            InitializeComponent();
        }
        public RadioTestControl(RadioTest test)
        {
            InitializeComponent();
            if(test == null)
                throw new ArgumentNullException();

            radioTest = test;
            Initialize();
        }

        private void Initialize()
        {
            radioTestQestionTextBox.Text = radioTest.QuestionText;
        }

        private void radioTestAddButton_Click(object sender, EventArgs e)
        {
            var textDialog = new TextEditDialog() { Value = string.Empty };
            if (textDialog.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(textDialog.Value))
            {
                var radioControl = new RadioButton() {Text = textDialog.Value};
                radioElementsPanel.Controls.Add(radioControl);
            }
        }

        private void radioTestEditButton_Click(object sender, EventArgs e)
        {
            if (ActiveControl is RadioButton && ActiveControl.Parent == radioElementsPanel)
            {
                var textDialog = new TextEditDialog()
                {
                    Value = ActiveControl.Text
                };
                if (textDialog.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(textDialog.Value))
                {
                    ActiveControl.Text = textDialog.Value;
                }
            }
        }

        private void radioTestRemoveButton_Click(object sender, EventArgs e)
        {
            if (ActiveControl is RadioButton && ActiveControl.Parent == radioElementsPanel)
            {
                radioElementsPanel.Controls.Remove(ActiveControl);
            }
        }

        public CheckTest GetTest()
        {
            return null;
            /*radioTest.QuestionText = radioTestQestionTextBox.Text;
            radioTest.Statements.Clear();
            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                checkTest.Statements.Add(new Pair<string, bool>((string)checkedListBox1.Items[i],
                    checkedListBox1.CheckedIndices.Contains(i)));
            }

            return checkTest;*/
        }
    }
}
